package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.Brand;

import com.itheima.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/brand")
@CrossOrigin
public class BrandControl {
    @Autowired
    private BrandService brandService;
    @GetMapping
    public Result findAll(){
        return brandService.findAll();
    }
    @PostMapping
    public Result add(@RequestBody Brand brand){
        return brandService.add(brand);
    }

    @RequestMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page")Integer page,@PathVariable("size")Integer size){
       return brandService.findPage(page,size);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id")Integer id){
        return brandService.findById(id);
    }
    @PutMapping("/{id}")
    public Result update(@PathVariable("id")Integer id,@RequestBody Brand brand){
        return brandService.updateId(id,brand);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id")Integer id){
        return brandService.deleteId(id);
    }
}
